﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fluent
{
    public class UIAssert
    {
        IWebDriver _browser;
        public UIAssert(IWebDriver browser)
        {
            _browser = browser;
        }

        public IWebElement AreExists(By by)
        {
            if (by == null)
            {
                throw new ArgumentNullException("by");
            }

            var elements = _browser.FindElements(by);

            if (elements.Count > 0)
            {
                return elements.First();
            }
            else
            {
                throw new NoSuchElementException(string.Format("The element is not exists.", by.ToString()));
            }
        }

        public IWebElement AreVisiable(By by)
        {
            var element = AreExists(by);

            Assert.IsTrue(element.Displayed, string.Format("The element is not visiable.", by.ToString()));

            return element;
        }

        public IWebElement AreHide(By by)
        {
            var element = AreExists(by);

            Assert.IsFalse(element.Displayed, string.Format("The element is not hide.", by.ToString()));

            return element;
        }

        public IWebElement AreTextEqual(By by, string expectedText)
        {
            var element = AreExists(by);

            Assert.AreEqual<string>(expectedText, element.Text, string.Format("The element's text dosen't match the expected value.", by.ToString()));

            return element;
        }
    }
}
